package logic;

import interfaze.SpaceInvadersGamingPanel;

import entities.Enemy;
import entities.Fighter;
import entities.Bouncer;

import java.util.ArrayList;

public class EarthDefenderLevelFiller {
	ArrayList<Enemy> aEnemies = new ArrayList<Enemy>();
	boolean bouncers;
	int velEnemY,velEnem;
	SpaceInvadersGamingPanel p;
	/**
	 * 
	 * @param p the panel on which to place the enemies
	 * @param velEnem the horizontal speed at which the enemies should move
	 * @param velEnemY the vertical speed at which the enemies should move
	 * @param bouncers whether a bouncer should be included or not
	 * @return
	 */
	public EarthDefenderLevelFiller(SpaceInvadersGamingPanel p,int velEnem, int velEnemY,boolean bouncers){
		this.bouncers=bouncers;
		this.velEnem=velEnem;
		this.velEnemY=velEnemY;
		this.p=p;
	}
	public ArrayList<ArrayList<Enemy>> addEnemigos() {
		ArrayList<ArrayList<Enemy>> listasEnemigos=new ArrayList<ArrayList<Enemy>>();
		aEnemies=new ArrayList<Enemy>();
		/**
		 * these two "for" will create all the rows of enemies, there is really not much to it
		 */
		for(int i=(int) (130*p.getYScale());i<p.window.getHeight()-250;i+=120*p.getYScale()){
			ArrayList<Enemy> filaEnemigos=new ArrayList<Enemy>();
			for(int j=(int) (50*p.getXScale());j<p.window.getWidth()-150;j+=150*p.getXScale()){
				Fighter temp=new Fighter(j, i, velEnem, velEnemY, p.getXScale(), p.getYScale(), filaEnemigos,p);
				filaEnemigos.add(temp);
				aEnemies.add(temp);
			}
			listasEnemigos.add(filaEnemigos);
		}
		/**
		 * the bouncer will not be included unless specified by the configuration file stored
		 */
		if(bouncers){
			ArrayList<Enemy> filaBouncer= new ArrayList<Enemy>();
			Bouncer bouncer=new Bouncer(p.window.getWidth()/2, 30, velEnem,0, p.getXScale(), p.getYScale(),filaBouncer,p);
			filaBouncer.add(bouncer);
			listasEnemigos.add(filaBouncer);
			aEnemies.add(bouncer);
		}
		/**
		 * this for each includes all the enemies in the specified SpaceInvadersGamingPanel
		 */
		for(Enemy e:aEnemies){
			p.add(e, 0);
			e.setVisible(true);
		}
		return listasEnemigos;
	}
}
